package LeetCode;

import java.util.Arrays;

public class problem1 {

    public static void main(String[] args) {
        int[] A = new int[2];
        int[] B = new int[]{1};
        merge(A,1,B,1);
        System.out.println(Arrays.toString(A));

    }

    public static void merge(int A[], int m, int B[], int n) {
        int i = m - 1;
        int j = n - 1;
        int k = n + m - 1;
        while(i>=0 && j>=0) {
            if(A[i] > B[j]) {
                A[k] = A[i];
                k--;
                i--;
            } else {
                A[k] = B[j];
                k--;
                j--;
            }
        }

        if(j >= 0) {
            System.arraycopy(B,0,A,0,j+1);
        }

    }
}

